<?php
namespace App\Http\Controllers\Wechat;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Repos\OrderRepo;
use App\Repos\UserAddressRepo;
use App\Repos\UserCouponRepo;
use App\Repos\UserGroupbuyRepo;
use App\Repos\UserRepo;
use App\Repos\CartRepo;
use App\Http\Requests\Api\OrderRequest;


class OrderController extends Controller
{
    public function makeOrder(OrderRequest $request)
    {
    	$rs['status'] = false;
    	$data = $request->pure();
    	$data['code'] = orderCode('C',$request->user_id);
    	
        // 购物车id
        $cart_ids  = array_pull($data,'cart_ids');
        $cart_ids  = explode(',', $cart_ids);
        //dd($cart_ids);
        $carts     = CartRepo::get($cart_ids);
        $data['total_money'] = $carts->sum('sub_total');
    	if($carts->isEmpty()) {
            $rs['msg'] = '没有选择购物车';
            return response()->json($rs);
        }

    	$ret = OrderRepo::create($data,$carts);
    	if($ret['status']==true) {
    		$rs['status'] = true;
    		$rs['data']   = $ret;
            return response()->json($rs);
    	}
        $rs['msg'] = $ret['msg'];
    	return response()->json($rs);
    }

 

    

   
}
